package com.keyroy.game.puzzle_rpg.models.attribute;

import com.keyroy.game.puzzle_rpg.models.item.RoleItem;
import com.keyroy.game.puzzle_rpg.models.role.Role;

public class ItemParam {
	public Strength strength = new Strength();
	public Dexterity dexterity = new Dexterity();
	public Knowledge knowledge = new Knowledge();
	public Vitality vitality = new Vitality();

	public HP life = new HP();
	public Speed speed = new Speed();

	public PhysicsDamage maxPhysicsDamage = new PhysicsDamage();
	public PhysicsDamage minPhysicsDamage = new PhysicsDamage();

	public MagicDamage maxMagicDamage = new MagicDamage();
	public MagicDamage minMagicDamage = new MagicDamage();

	public PhysicsDefense physicsDefense = new PhysicsDefense();
	public MagicDefense magicDefense = new MagicDefense();

	private ItemParam() {
	}

	public static ItemParam compute(Role role) {
		ItemParam itemParam = new ItemParam();
		find(role.strength, itemParam);
		find(role.dexterity, itemParam);
		find(role.knowledge, itemParam);
		find(role.vitality, itemParam);
		find(role.hp, itemParam);
		find(role.speed, itemParam);

		find(role.hat, itemParam);
		find(role.armour, itemParam);
		find(role.ring, itemParam);
		find(role.gloves, itemParam);
		find(role.speed, itemParam);
		find(role.weapon, itemParam);
		find(role.shield, itemParam);
		find(role.shoe, itemParam);
		return itemParam;
	}

	private static final void find(RoleItem roleItem, ItemParam itemParam) {
		if (roleItem != null) {
			for (int i = 0; i < roleItem.effect.size(); i++) {
				Param param = roleItem.effect.get(i);
				find(param, itemParam);
			}
		}
	}

	private static final void find(Param param, ItemParam itemParam) {
		if (param != null) {
			if (param instanceof Strength) {
				itemParam.strength.value += param.value;
			} else if (param instanceof Dexterity) {
				itemParam.dexterity.value += param.value;
			} else if (param instanceof Knowledge) {
				itemParam.knowledge.value += param.value;
			} else if (param instanceof Vitality) {
				itemParam.vitality.value += param.value;
			} else if (param instanceof HP) {
				itemParam.life.value += param.value;
			} else if (param instanceof Speed) {
				itemParam.speed.value += param.value;
			} else if (param instanceof PhysicsDamage) {
				itemParam.maxPhysicsDamage.value += param.value;
				itemParam.minPhysicsDamage.value += param.value;
			} else if (param instanceof MagicDamage) {
				itemParam.maxMagicDamage.value += param.value;
				itemParam.minMagicDamage.value += param.value;
			} else if (param instanceof PhysicsDefense) {
				itemParam.physicsDefense.value += param.value;
			} else if (param instanceof MagicDefense) {
				itemParam.magicDefense.value += param.value;
			} else if (param instanceof RandomParam) {
				RandomParam randomParam = (RandomParam) param;
				if (randomParam.clazz != null) {
					if (randomParam.clazz.equals(PhysicsDamage.class)) {
						itemParam.minPhysicsDamage.value += randomParam.getMin();
						itemParam.maxPhysicsDamage.value += randomParam.getMax();
					} else if (randomParam.clazz.equals(MagicDamage.class)) {
						itemParam.minMagicDamage.value += randomParam.getMin();
						itemParam.maxMagicDamage.value += randomParam.getMax();
					}
				}
			}
		}
	}

}
